﻿using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;

namespace VteamProjectAssistant.SettingWindow
{
    /// <summary>
    /// SettingWindowView.xaml 的交互逻辑
    /// </summary>
    public partial class SettingWindowView : Window
    {

        Regex regex = new Regex("^[a-zA-Z0-9.]+$");

        public SettingWindowView(SettingWindowViewModel settingWindowViewModel)
        {
            InitializeComponent();
            DataContext = settingWindowViewModel;
        }

        private void UserName_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            // 检查输入的文本是否合法
            if (!regex.IsMatch(e.Text))
            {
                e.Handled = true;
            }
        }

        private void Window_Loaded(object sender, RoutedEventArgs e)
        {
            // 获取ViewModel实例
            if (DataContext is SettingWindowViewModel viewModel)
            {
                // 执行初始化命令
                viewModel.LoadAuthenticationInfoCommand.Execute(null);
            }
        }

        private void Common_TextChanged(object sender, TextChangedEventArgs e)
        {
            // 获取ViewModel实例
            if (DataContext is SettingWindowViewModel viewModel)
            {
                // 执行初始化命令
                viewModel.CanSave = userNameInput.Text.Length >0 && passwordInput.Text.Length > 0;
            }
        }
    }
}
